package tp.pr4.items;

import tp.pr4.NavigationModule;
import tp.pr4.RobotEngine;

/**
 * The garbage is a type of item that generates recycled material after 
 * using it. The garbage can be used only once. After using it, it must 
 * be removed from the robot inventory
 * @author Alvaro Saez Hernando
 * @author Noel Clemente Montero 
 */
public class Garbage extends Item{
	
	private int recycledMaterial;
	private boolean used;
	
	/**
	 * Garbage constructor
	 * @param id Item id
	 * @param description Item description
	 * @param recycledMaterial The amount of recycled material that the item generates
	 */
	public Garbage(String id,String description,int recycledMaterial){
		super(id,description);
		this.recycledMaterial = recycledMaterial;
		used = false;
	}
	
	/**
	 * Garbage can be used only once
	 * @return true if the item has not been used yet
	 */
	public boolean canBeUsed(){
		return !used;
	}
	
	/**
	 * The garbage generates recycled material for the robot that uses it
	 * @param r the robot engine
	 * @param nav The navigation module
	 * @return true if the garbage was transformed in recycled material
	 */
	public boolean use(RobotEngine r, NavigationModule nav){
		boolean used = false;
		if(canBeUsed()){
			r.addRecycledMaterial(this.recycledMaterial);
			used = true;
			this.used=true;
			r.printRobotState();
		}
		return used;
	}
	
	/**
	 * Generates a String with the Item description
	 */
	public String toString(){
		return super.toString() + "// recycle material = " + this.recycledMaterial;
	}


}
